package com.quanyan.util;


import com.alibaba.fastjson.JSON;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.quanyan.api.APIRequest;
import com.quanyan.assets.request.*;
import com.quanyan.orderpay.request.*;
import com.quanyan.place.entity.vo.ReqPlaceUnitSearch;
import org.apache.log4j.Logger;

import java.math.BigDecimal;

;

public class TypeUtil {
    private static final Logger log=Logger.getLogger(TypeUtil.class);
    public static Object[] typeTransform(Class<?>[] parameterTypes, String[] dataStr, String clazzName, String methodName) {
        //byte short int long char float double boolean String
        Gson gson = new Gson();
        if (parameterTypes == null || parameterTypes.length == 0 || dataStr == null || "".equals(dataStr))
            return null;
        Object[] obj = new Object[dataStr.length];
        for (int i = 0; i < dataStr.length; i++) {
            String type = parameterTypes[i].getName();
            if ("java.lang.Byte".equals(type) || "byte".equals(type.toLowerCase())) {
                obj[i] = Byte.parseByte(dataStr[i]);
            } else if ("java.lang.Short".equals(type) || "short".equals(type.toLowerCase())) {
                obj[i] = Short.parseShort(dataStr[i]);
            } else if ("java.lang.Integer".equals(type) || "int".equals(type.toLowerCase()) || "Integer".equals(type)) {
                obj[i] = Integer.parseInt(dataStr[i]);
            } else if ("java.lang.Long".equals(type) || "long".equals(type.toLowerCase())) {
                obj[i] = Long.parseLong(dataStr[i]);
            } else if ("java.lang.Character".equals(type) || "char".equals(type.toLowerCase()) || "Character".equals(type)) {
                obj[i] = dataStr[i].charAt(0);
            } else if ("java.lang.Float".equals(type) || "float".equals(type.toLowerCase())) {
                obj[i] = Float.parseFloat(dataStr[i]);
            } else if ("java.lang.Double".equals(type) || "double".equals(type.toLowerCase())) {
                obj[i] = Double.parseDouble(dataStr[i]);
            } else if ("java.math.BigDecimal".equals(type) || "bigdecimal".equals(type.toLowerCase())) {
                obj[i] = new BigDecimal(dataStr[i]);
            } else if ("java.lang.String".equals(type) || "string".equals(type.toLowerCase())) {
                obj[i] = dataStr[i];
            } else if ("com.quanyan.place.entity.vo.ReqPlaceUnitSearch".equals(type)) {
                ReqPlaceUnitSearch reqPlaceUnitSearch = JSON.parseObject(dataStr[i], ReqPlaceUnitSearch.class);
                obj[i] = reqPlaceUnitSearch;
                log.warn("methodName:"+methodName+"      service change request data "+JSON.toJSONString(reqPlaceUnitSearch));
            } else if ("com.quanyan.api.APIRequest".equals(type) && "orderPayService".equals(clazzName) && "submitOrder".equals(methodName)) {
                APIRequest<ReqOrderSave> apiRequest = gson.fromJson(dataStr[i], new TypeToken<APIRequest<ReqOrderSave>>() {
                }.getType());
                obj[i] = apiRequest;
                log.warn("methodName:"+methodName+"      service change request data "+apiRequest.toString());
            } else if ("com.quanyan.api.APIRequest".equals(type) && "orderPayService".equals(clazzName) && "refundApply".equals(methodName)) {
                APIRequest<ReqOrderRefund> apiRequest = gson.fromJson(dataStr[i], new TypeToken<APIRequest<ReqOrderRefund>>() {
                }.getType());
                obj[i] = apiRequest;
                log.warn("methodName:"+methodName+"      service change request data "+apiRequest.toString());
            } else if ("com.quanyan.api.APIRequest".equals(type) && "orderPayService".equals(clazzName) && "orderCancel".equals(methodName)) {
                APIRequest<ReqOrderCancel> apiRequest = gson.fromJson(dataStr[i], new TypeToken<APIRequest<ReqOrderCancel>>() {
                }.getType());
                obj[i] = apiRequest;
                log.warn("methodName:"+methodName+"      service change request data "+apiRequest.toString());
            } else if ("com.quanyan.api.APIRequest".equals(type) && "userAssetsService".equals(clazzName) && "getUserAccumulateList".equals(methodName)) {
                APIRequest<ReqUserInfo> apiRequest = gson.fromJson(dataStr[i], new TypeToken<APIRequest<ReqUserInfo>>() {
                }.getType());
                obj[i] = apiRequest;
                log.warn("methodName:"+methodName+"      service change request data "+apiRequest.toString());
            } else if ("com.quanyan.api.APIRequest".equals(type) && "userAssetsService".equals(clazzName) && "add".equals(methodName)) {
                APIRequest<ReqUserAssets> apiRequest = gson.fromJson(dataStr[i], new TypeToken<APIRequest<ReqUserAssets>>() {
                }.getType());
                obj[i] = apiRequest;
                log.warn("methodName:"+methodName+"      service change request data "+apiRequest.toString());
            } else if ("com.quanyan.api.APIRequest".equals(type) && "userAssetsService".equals(clazzName) && "modifyAccumulate".equals(methodName)) {
                APIRequest<ReqUserAccumulateModify> apiRequest = gson.fromJson(dataStr[i], new TypeToken<APIRequest<ReqUserAccumulateModify>>() {
                }.getType());
                obj[i] = apiRequest;
                log.warn("methodName:"+methodName+"      service change request data "+apiRequest.toString());
            } else if ("com.quanyan.api.APIRequest".equals(type) && "userAssetsService".equals(clazzName) && "modifyAccumulateBatch".equals(methodName)) {
                APIRequest<ReqUserAccumulateModifyBatch> apiRequest = gson.fromJson(dataStr[i], new TypeToken<APIRequest<ReqUserAccumulateModifyBatch>>() {
                }.getType());
                obj[i] = apiRequest;
                log.warn("methodName:"+methodName+"      service change request data "+apiRequest.toString());
            } else if ("com.quanyan.api.APIRequest".equals(type) && "userAssetsService".equals(clazzName) && "getUserAccumulateAndRule".equals(methodName)) {
                APIRequest<ReqRuleDetail> apiRequest = gson.fromJson(dataStr[i], new TypeToken<APIRequest<ReqRuleDetail>>() {
                }.getType());
                obj[i] = apiRequest;
                log.warn("methodName:"+methodName+"      service change request data "+apiRequest.toString());
            } else if ("com.quanyan.api.APIRequest".equals(type) && "userAssetsService".equals(clazzName) && "freezeAccumulate".equals(methodName)) {
                APIRequest<ReqUserAccumulateModify> apiRequest = gson.fromJson(dataStr[i], new TypeToken<APIRequest<ReqUserAccumulateModify>>() {
                }.getType());
                obj[i] = apiRequest;
                log.warn("methodName:"+methodName+"      service change request data "+apiRequest.toString());
            } else if ("com.quanyan.api.APIRequest".equals(type) && "userAssetsService".equals(clazzName) && "freezeAccumulateBatch".equals(methodName)) {
                APIRequest<ReqUserAccumulateModifyBatch> apiRequest = gson.fromJson(dataStr[i], new TypeToken<APIRequest<ReqUserAccumulateModifyBatch>>() {
                }.getType());
                obj[i] = apiRequest;
                log.warn("methodName:"+methodName+"      service change request data "+apiRequest.toString());
            } else if ("com.quanyan.api.APIRequest".equals(type) && "userAssetsService".equals(clazzName) && "unfreezeAccumulateSuccess".equals(methodName)) {
                APIRequest<ReqUnfreeze> apiRequest = gson.fromJson(dataStr[i], new TypeToken<APIRequest<ReqUnfreeze>>() {
                }.getType());
                obj[i] = apiRequest;
                log.warn("methodName:"+methodName+"      service change request data "+apiRequest.toString());
            } else if ("com.quanyan.api.APIRequest".equals(type) && "userAssetsService".equals(clazzName) && "unfreezeAccumulateFail".equals(methodName)) {
                APIRequest<ReqUnfreeze> apiRequest = gson.fromJson(dataStr[i], new TypeToken<APIRequest<ReqUnfreeze>>() {
                }.getType());
                obj[i] = apiRequest;
                log.warn("methodName:"+methodName+"      service change request data "+apiRequest.toString());
            } else if ("com.quanyan.api.APIRequest".equals(type) && "userAssetsService".equals(clazzName) && "refund".equals(methodName)) {
                APIRequest<ReqRefund> apiRequest = gson.fromJson(dataStr[i], new TypeToken<APIRequest<ReqRefund>>() {
                }.getType());
                obj[i] = apiRequest;
                log.warn("methodName:"+methodName+"      service change request data "+apiRequest.toString());
            } else if ("com.quanyan.orderpay.request.ReqSysPayInfo".equals(type) && "orderPayService".equals(clazzName) && "applyEnablePayInfos".equals(methodName)) {
                ReqSysPayInfo reqSysPayInfo = JSON.parseObject(dataStr[i], ReqSysPayInfo.class);
                obj[i] = reqSysPayInfo;
                log.warn("methodName:"+methodName+"      service change request data "+JSON.toJSONString(reqSysPayInfo));
            } else if ("com.quanyan.orderpay.request.ReqSysPayInfo".equals(type) && "orderPayService".equals(clazzName) && "selectEnablePayInfos".equals(methodName)) {
                ReqSysPayInfo reqSysPayInfo = JSON.parseObject(dataStr[i], ReqSysPayInfo.class);
                obj[i] = reqSysPayInfo;
                log.warn("methodName:"+methodName+"      service change request data "+JSON.toJSONString(reqSysPayInfo));
            } else if ("com.quanyan.orderpay.request.ReqWithdrawApply".equals(type) && "orderPayService".equals(clazzName) && "applyWithdraw".equals(methodName)) {

                ReqWithdrawApply reqWithdrawApply = JSON.parseObject(dataStr[i], ReqWithdrawApply.class);
                obj[i] = reqWithdrawApply;
                log.warn("methodName:"+methodName+"      service change request data "+JSON.toJSONString(reqWithdrawApply));
            } else if ("com.quanyan.api.APIRequest".equals(type) && "orderPayService".equals(clazzName) && "getWeichatAccount".equals(methodName)) {
                APIRequest<ReqWeichatAccount> apiRequest = gson.fromJson(dataStr[i], new TypeToken<APIRequest<ReqWeichatAccount>>() {
                }.getType());
                obj[i] = apiRequest;
                log.warn("methodName:"+methodName+"      service change request data "+apiRequest.toString());
            } else if ("com.quanyan.api.APIRequest".equals(type) && "orderPayService".equals(clazzName) && "batchRefundApply".equals(methodName)) {
                APIRequest<ReqBatchOrderRefund> apiRequest = gson.fromJson(dataStr[i], new TypeToken<APIRequest<ReqBatchOrderRefund>>() {
                }.getType());
                obj[i] = apiRequest;
                log.warn("methodName:"+methodName+"      service change request data "+apiRequest.toString());
            } else if ("com.quanyan.api.APIRequest".equals(type) && "orderPayService".equals(clazzName) && "auditRefundApply".equals(methodName)) {
                APIRequest<ReqAuditEntity> apiRequest = gson.fromJson(dataStr[i], new TypeToken<APIRequest<ReqAuditEntity>>() {
                }.getType());
                obj[i] = apiRequest;
                log.warn("methodName:"+methodName+"      service change request data "+apiRequest.toString());
            }  else {//com.quanyan.api.APIRequest
                obj[i] = null;
            }
        }

        return obj;
    }
}
